SET(PROJ_NAME endless)

file(GLOB_RECURSE CPP_SOURCE_FILE "*.cpp")
file(GLOB_RECURSE CPP_HEADERS_FILE "*.hpp")
file(GLOB_RECURSE C_SOURCE_FILE "*.c")
file(GLOB_RECURSE C_HEADERS_FILE "*.h")

set(ALL_HDRS ${CPP_HEADERS_FILE} ${C_HEADERS_FILE})
set(ALL_SOURCES ${CPP_SOURCE_FILE} ${C_SOURCE_FILE})

link_libraries(-Wl,--start-group ${EL_ALL_LIBS} -Wl,--end-group)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "m64x86")
    message("Building for m64x86 platform")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
    message("Building for aarch64 platform")
endif()

add_executable(${PROJ_NAME} ${ALL_SOURCES} ${ALL_HDRS})

# 创建输出目录
set(OUTPUT_BIN_DIR ${CMAKE_SOURCE_DIR}/out/bin)
file(MAKE_DIRECTORY ${OUTPUT_BIN_DIR})

# 复制可执行文件到out/bin目录
add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJ_NAME}> ${OUTPUT_BIN_DIR}/${PROJ_NAME}
    COMMENT "Copying ${PROJ_NAME} to ${OUTPUT_BIN_DIR}"
)
